#include <iostream>
#include <climits>
#include <cstring>
using namespace std;
using LL=long long;
const int N=60;
const int M=30;
const int INF=0x3f3f3f3f;
LL n;


int w[N];
LL dp[N][N][M];
static LL c[M];
void add(LL a[],LL b[])
{
	LL t=0;
	memset(c,0,sizeof(c));
	for(int i=0;i<M;i++)
	{
		t+=a[i]+b[i];
		c[i]=t%10;
		t/=10;
	}
	memcpy(a,c,sizeof(c));
}
void mul(LL a[],LL b)
{
	memset(c,0,sizeof(0));
	LL t=0;
	for(int i=0;i<M;i++)
	{
		t+=a[i]*b;
		c[i]=t%10;
		t/=10;
	}
	memcpy(a,c,sizeof(c));
}
int cmp(LL a[], LL b[])
{
    for (int i = M - 1; i >= 0; i -- )
        if (a[i] > b[i]) return 1;
        else if (a[i] < b[i]) return -1;
    return 0;
}
void Print(LL a[])
{
	int k=M-1;
	while(k>=0 && a[k]==0)
		k--;
	for(;k>=0;k--)
	{
		printf("%lld",a[k]);
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&w[i]);
	LL tmp[M];	
	for(int len=3;len<=n;len++)
	{
		for(int l=1;l+len-1<=n;l++)
		{
			int r=l+len-1;
			dp[l][r][M-1]=1;
			for(int k=l+1;k<r;k++)
			{
				memset(tmp,0,sizeof(tmp));
				tmp[0]=w[l];
				mul(tmp,w[r]);
				mul(tmp,w[k]);
				add(tmp,dp[l][k]);
				add(tmp,dp[k][r]);
				if(cmp(dp[l][r],tmp)>0)
				{
					memcpy(dp[l][r],tmp,sizeof(tmp));
				}
				
			}
		}
		
	}
	Print(dp[1][n]);
	return 0;
}
